// JavaScript Document
$(function(){
	/*表单提交*/
	$(".btn").click(function(){
        var old_pwd = $("#old_pwd").val();
        var new_pwd = $("#new_pwd").val();
        var confirm_pwd = $("#confirm_pwd").val();
        var pT = /^([a-z]|[A-Z]|[0-9]){6,20}$/;
        if(old_pwd==''){
            show_err_msg('原密码还没填呢！');
            return false;
        }else if(!pT.test(old_pwd)){
            show_err_msg("原密码只能为字母和数字。长度在6~20位之间");
            return false;
        }else if(new_pwd==''){
            show_err_msg('新密码还没填呢！');
        }else if(!pT.test(new_pwd)){
            show_err_msg("新密码只能为字母和数字。长度在6~20位之间");
            return false;
        }else if(new_pwd== old_pwd){
            show_err_msg('新密码不能与旧密码相同！');
        }else if(confirm_pwd==''){
            show_err_msg('确认密码还没填呢！');
        }else if(!pT.test(confirm_pwd)){
            show_err_msg("确认密码只能为字母和数字。长度在6~20位之间");
            return false;
        }else if(confirm_pwd != new_pwd){
            show_err_msg('两个密码不一致！');
        }else{
            updatePassword(old_pwd,new_pwd);
        }
	});	
});
function updatePassword(old_pwd,new_pwd){
	if(ajaxFun("/ajax/checkAuthority/?functionId=web_user_setPwd&deptId=")){
        var xmlhttp;
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var obj;
                try{
                    obj =  eval('(' + xmlhttp.responseText + ')');
                }catch(exception){
                    obj="error";
                }
                if(obj == "error"){
                    show_err_msg("服务链接出错！");    
                }else{
                    if(obj.status == "succeed"){
                        show_msg(obj.info,"");
                       // window.open('/index/','_SELF');
                       window.location.href='/index/';
                    }else{
                        show_err_msg(obj.info);
                    }
                }
            }
        }
        xmlhttp.open("POST", "/ajax/updatePassword/", true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.send("old_pwd="+old_pwd+"&new_pwd="+new_pwd);
    }else{
        show_err_msg("您目前没有修改密码的权限,请联系管理员");
        return false;
    }
}